#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#define ARGS_CHECK(argc, num)                 \
    {                                         \
        if (argc != num)                      \
        {                                     \
            fprintf(stderr, "args error!\n"); \
            return -1;                        \
        }                                     \
    }
#define ERROR_CHECK(ret, num, msg) \
    {                              \
        if (ret == num)            \
        {                          \
            perror(msg);           \
            exit(1);               \
        }                          \
    }
int main(int argc, char *argv[])
{
    int fd_b = socket(PF_INET,SOCK_DGRAM,0);
    ERROR_CHECK(-1,fd_b,"socket");
    int on = 1;
    if (-1 == setsockopt(fd_b,SOL_SOCKET,SO_BROADCAST,&on,sizeof on))
    {
        perror("setsockopt");
        return -1;
    }
    struct sockaddr_in saddr;
    saddr.sin_family = PF_INET;
    saddr.sin_port =htons(8888);
    saddr.sin_addr.s_addr = inet_addr("192.168.12.255");
    if (-1 == bind(fd_b,(void *)&saddr,sizeof saddr))
    {
        perror("bind");
    }
    char buf[1024];
    while (1)
    {
       fgets(buf,1024,0);
        sendto(fd_b,buf,1024,0,(void *)&saddr,sizeof saddr);
    }
    
    return 0;
}
